/**
  * Author: Mei
  * Date: 2020-11-20 14:38
  * Description: 
  *
  */
#include <iostream>
#include <atomic>
#include <thread>
#include <vector>

using namespace std;

void func(atomic<int> &counter) {
    int result = 0;
    for (int i = 0; i < 100; ++i) {
        ++result;
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
    }
    counter += result;
}

int main() {
    atomic<int> count(0);
    std::vector<std::thread> threads;
    for (int i = 0; i < 10; ++i) {
        threads.push_back(std::thread{func, std::ref(count)});
    }

    for(int i = 0; i < threads.size(); ++i) {
        threads[i].join();
    }
    //for (auto t : threads) {
    //    t.join();
    //}
    cout << "Result = " << count << endl;
    return 0;
}